{% if product.variant.size > 1 %}
  {% assign selected_variant = product.selected_or_first_available_variant | remove: "/" %}
  <script onload="loadTryOnButton({
      psku:'{{ selected_variant }}',
      page:'product',
      tryonBtnId:'custom_tryonbutton',
      regionId:'2',
      cacheNum:'26',
      company:'store-rokid',
      buynow:{enable:'true'},
      buynowCallback:'onTryOnBuynowCallback',
      });" src="{{ 'camweara_api.js' | asset_url }}" async></script>
{% else %}
{% assign sku_tryon_pdp = product.variants.first.sku | remove: "/" %}
<script onload="loadTryOnButton({
      psku:'{{ sku_tryon_pdp }}',
      page:'product',
      tryonBtnId:'custom_tryonbutton',
      regionId:'2',
      cacheNum:'26',
      company:'store-rokid',
      buynow:{enable:'true'},
      buynowCallback:'onTryOnBuynowCallback',
      });" src="{{ 'camweara_api.js' | asset_url }}" async></script>
{% endif %}
<script> 
      function onTryOnBuynowCallback(sku) {
        console.log("onTryOnBuynowCallback entered");
        if (window.history.length > 1) {
          window.history.back();
        } else {
          window.close(); // Only works for JS-opened tabs
        }
      }
</script>